package com.weiawei.Dialog;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class BackDialog extends baseDialog {
    public static int cancel = 0;
    public static int back = 1;
    private JButton backButton, cancelButton;
    private JLabel jLabel;

    /**
     * BackDialog的构造函数
     *
     * @param jFrame
     * @param title  对话框标题
     * @param b
     */
    public BackDialog(JFrame jFrame, String title, boolean b) {
        super(jFrame, title, b);
        this.init();
    }

    /**
     * 初始化返回对话框
     *
     * <p>初始化内容包括选项与内容</p>
     */
    private void init() {
        backButton = new JButton("返回菜单");
        cancelButton = new JButton("取  消");
        jLabel = new JLabel();

        this.setRightButton(backButton);
        this.setLeftButton(cancelButton);

        jLabel.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
        jLabel.setBounds(80, 10, 200, 100);
        jLabel.setText("确定要返回主菜单吗？");

        add(backButton);
        add(cancelButton);
        add(jLabel);
    }

    /**
     * 通过用户点击的按键来相应不同的事件
     *
     * <p>当用户点击重新开始时重新开始一局游戏
     * 当用户点击返回时返回初始菜单</p>
     *
     * @param e 用户点击的按键
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == cancelButton) {
            message = cancel;
            setVisible(false);
        } else if (e.getSource() == backButton) {
            message = back;
            setVisible(false);
        }
    }
}
